package org.jetlinks.pro.device.service.task;

import org.hswebframework.web.api.crud.entity.PagerResult;
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
import org.jetlinks.core.message.DeviceMessage;
import org.jetlinks.core.message.DeviceMessageReply;
import org.jetlinks.pro.device.enums.TaskState;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Collection;
import java.util.List;

/**
 * 设备消息任务持久化仓库,提供对设备消息任务对持久化
 *
 * @author zhouhao
 * @since 1.10
 */
public interface DeviceMessageTaskRepository {

    /**
     * 添加多个任务
     *
     * @param tasks 任务列表
     * @return void
     * @see DeviceMessageTask#newTask(DeviceMessage)
     */
    Mono<Void> addTasks(List<DeviceMessageTask> tasks);

    /**
     * 添加单个任务
     *
     * @param task 任务列表
     * @return void
     * @see DeviceMessageTask#newTask(DeviceMessage)
     */
    Mono<Void> addTask(DeviceMessageTask task);

    /**
     * 更新任务响应
     *
     * @param response 响应
     * @return void
     * @see DeviceMessageResponse#of(DeviceMessage, DeviceMessageReply)
     * @see DeviceMessageResponse#of(DeviceMessage, Throwable)
     */
    Mono<Void> updateResult(DeviceMessageResponse response);

    /**
     * 分页查询任务信息
     *
     * @param query 动态查询条件
     * @return 分页查询结果
     */
    Mono<PagerResult<DeviceMessageTask>> queryPager(QueryParamEntity query);

    /**
     * 动态查询任务信息
     *
     * @param query 查询条件
     * @return 查询结果
     */
    Flux<DeviceMessageTask> query(QueryParamEntity query);

    /**
     * 根据ID获取任务信息
     *
     * @param id ID
     * @return 任务信息
     */
    Mono<DeviceMessageTask> findById(String id);

    /**
     * 修改任务状态
     * @param taskId 多个任务ID
     * @param state 状态
     * @return void
     */
    Mono<Void> changeState(Collection<String> taskId,TaskState state);
}
